<?php
/**
 * Smart Library - Smart Framework
 * http://smart-framework.highet.eu
 *
 * @category   SmartL
 * @package    SmartL_Profiler
 * @copyright  Copyright (c) 2005-2008 Smart Framework team - Stepan Sindelar, Vojtech Vit
 * @license    http://www.opensource.org/licenses/bsd-license.php	New BSD License
 */

/**
 * @see SmartL_Profiler
 */
require_once 'SmartL/Profiler.php';
/**
 * @see SmartL_Application_Plugin_Abstract
 */
require_once 'SmartL/Application/Plugin/Abstract.php';

/**
 * @package SmartL_Profiler
 */
class SmartL_Profiler_Plugin extends SmartL_Application_Plugin_Abstract {
	/**
	 * @var SmartL_Profiler
	 */
	private $_profiler;
	
	public function __construct() {
		$this->_profiler = SmartL_Profiler::getInstance ();
	}
	
	public function dispatchLoopShutdown() {
		$this->_profiler->checkMemory ( "dispatchLoopShutdown" );
		$this->_profiler->stop ();
		if ($this->_profiler->getAppendResultToResponseFlag ()) {
			Zend_Controller_Front::getInstance ()->getResponse ()->appendBody ( $this->_profiler->renderResult () );
		}
	}
	
	public function preLoadApplicationConfiguration() {
		$this->_profiler->checkMemory ( "preLoadApplicationConfiguration" );
		$this->_profiler->start ( "LoadApplicationConfiguration" );
	}
	
	public function postLoadApplicationConfiguration() {
		$this->_profiler->stop ( "LoadApplicationConfiguration" );
		$this->_profiler->checkMemory ( "postLoadApplicationConfiguration" );
	}
	
	public function preSetUpFrontController() {
		$this->_profiler->checkMemory ( "preSetUpFrontController" );
		$this->_profiler->start ( "SetUpFrontController" );
	}
	
	public function postSetUpFrontController() {
		$this->_profiler->stop ( "SetUpFrontController" );
		$this->_profiler->checkMemory ( "postSetUpFrontController" );
	}
	
	public function preSetUpLanguages() {
		$this->_profiler->checkMemory ( "preSetUpLanguages" );
		$this->_profiler->start ( "SetUpLanguages" );
	}
	
	public function postSetUpLanguages() {
		$this->_profiler->stop ( "SetUpLanguages" );
		$this->_profiler->checkMemory ( "postSetUpLanguages" );
	}
	
	public function preOpenDbConnections() {
		$this->_profiler->checkMemory ( "preOpenDbConnections" );
		$this->_profiler->start ( "openDbConnections" );
	}
	
	public function postOpenDbConnections() {
		$this->_profiler->checkMemory ( "postOpenDbConnections" );
		$this->_profiler->stop ( "openDbConnections" );
	}
	
	public function preAuthenticateUser() {
		$this->_profiler->checkMemory ( "preAuthenticateUser" );
		$this->_profiler->start ( "authenticateUser" );
	}
	
	public function postAuthenticateUser() {
		$this->_profiler->checkMemory ( "postAuthenticateUser" );
		$this->_profiler->stop ( "authenticateUser" );
	}
	
	public function preAuthorizeUser() {
		$this->_profiler->checkMemory ( "preAuthorizeUser" );
		$this->_profiler->start ( "authorizeUser" );
	}
	
	public function postAuthorizeUser() {
		$this->_profiler->stop ( "authorizeUser" );
		$this->_profiler->checkMemory ( "postAuthorizeUser" );
	}
	
	public function preInitModule($moduleName) {
		$this->_profiler->checkMemory ( "preInitModule" );
		$this->_profiler->start ( "initModule" );
	}
	
	public function postInitModule() {
		$this->_profiler->stop ( "initModule" );
		$this->_profiler->checkMemory ( "postInitModule" );
	}
	
	public function preLoadModuleConfiguration() {
		$this->_profiler->checkMemory ( "preLoadModuleConfiguration" );
		$this->_profiler->start ( "loadModuleConfiguration" );
	}
	
	public function postLoadModuleConfiguration() {
		$this->_profiler->stop ( "loadModuleConfiguration" );
		$this->_profiler->checkMemory ( "postLoadModuleConfiguration" );
	}
	
	public function preSetUpUserPreferences() {
		$this->_profiler->checkMemory ( "preSetUpUserPreferences" );
		$this->_profiler->start ( "setUpUserPreferences" );
	}
	
	public function postSetUpUserPreferences(SmartL_Application_Login_UserPreferences_Interface $preferences = null) {
		$this->_profiler->stop ( "setUpUserPreferences" );
		$this->_profiler->checkMemory ( "postSetUpUserPreferences" );
	}
	
	public function preStartLayout() {
		$this->_profiler->checkMemory ( "preStartLayout" );
		$this->_profiler->start ( "startLayout" );
	}
	
	public function postStartLayout($started) {
		$this->_profiler->stop ( "startLayout" );
		$this->_profiler->checkMemory ( "postStartLayout" );
	}
	
	public function routeStartup(Zend_Controller_Request_Abstract $request) {
		$this->_profiler->checkMemory ( "routeStartup" );
		$this->_profiler->start ( "routeStartUp" );
	}
	
	public function routeShutdown(Zend_Controller_Request_Abstract $request) {
		$this->_profiler->stop ( "routeStartUp" );
		$this->_profiler->checkMemory ( "routeShutdown" );
	}
	
	public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
		$this->_profiler->checkMemory ( "dispatchLoopStartup" );
		$this->_profiler->start ( "dispatchLoop" );
	}
	
	public function preDispatch(Zend_Controller_Request_Abstract $request) {
		$this->_profiler->checkMemory ( "preDispatch" );
	}
	
	public function postDispatch(Zend_Controller_Request_Abstract $request) {
		$this->_profiler->stop ( "dispatchLoop" );
		$this->_profiler->checkMemory ( "postDispatch" );
	}
}